	
	* Note: Due to the large file sizes the maps may take a minute or two to generate.
	
	clear
		shp2dta using "ne_10m_admin_0_countries.shp", data(trialdata) coordinates(trialcoord) replace
		use "trialdata.dta"
		rename GEOUNIT country
		do "COW code generator 20170809.do"
		rename cowcode COWCODE
		sort COWCODE 
			
			egen COWCODESUB = seq() 
			replace COWCODE = (COWCODESUB+1000) if COWCODE == .
			
		tempfile clear
		tempfile map_temp
		save `map_temp', replace
		
		
	clear
		use "Data_20170719.dta"
		keep if year>= 2001 & year <= 2011
		collapse (max) totalpeacekeepers troops duration_pk_totalpeacekeepers, by(ccode)
		rename ccode COWCODE
		replace COWCODE = 255 if COWCODE == 260
		duplicates tag COWCODE, gen(tag)
		drop if COWCODE == 255 & troops == .
		drop if COWCODE == .
		sort COWCODE 

		tempfile troops
		save `troops', replace

		merge 1:1 COWCODE using `map_temp', nogen
		replace troops = . if troops == 0
		replace totalpeacekeepers = . if totalpeacekeepers == 0
		drop if country == "Antarctica"

		replace country = "Bosnia" if country == "Bosnia and Herzegovina"
		replace country = "Serbia" if country == "Republic of Serbia"
		replace country = "Rep. of Congo" if country == "Republic of the Congo"
		replace country = "Congo Kinshasa" if country == "Democratic Republic of the Congo"
		replace country = "North Sudan" if country == "Sudan"
		
		graph bar duration_pk_totalpeacekeepers if duration_pk_totalpeacekeepers>0 & duration_pk_totalpeacekeepers!=., over(country, sort(duration_pk_totalpeacekeepers) label(angle(45))) ///
		ytitle(Duration in Years) ///
		plotregion(lwidth(0)) ///
		name(durationbar, replace)

		* Max UN Peacekeeping deployment to each state, 2011-2011 Color
		spmap totalpeacekeepers using trialcoord, id(_ID) fcolor(Heat) ndocolor(black) ocolor(black) ndfcolor(gs14) ///
		legtitle("UN Peacekeeping Personnel") legend(label(1 "0") pos(7) ring(0)) legstyle(2) clmethod(custom) clbreaks(1 100 1000 5000 10000 20000 30000) gsize(6) ///
		plotregion(margin(-1 -1 0 0)) graphregion(margin(0 0 -20 -10)) xsize(7) ysize(4) ndsize(.05) osize(.04 .04 .04 .04 .04 .04 .04 .04) mosize(.05) ///
		name(UN, replace) 
		 
		graph combine UN durationbar, cols(1) iscale(.9) imargin(0 0 0 0)  
		graph export "Deployment Map UN Duration 2.pdf", replace

		
		* Max UN Peacekeeping deployment to each state, 2011-2011, Grayscale
		spmap totalpeacekeepers using trialcoord, id(_ID) fcolor(Greys) ndocolor(black) ocolor(black) ndfcolor(white) ///
		legtitle("UN Peacekeeping Personnel") legend(label(1 "0") pos(7) ring(0)) legstyle(2) clmethod(custom) clbreaks(1 100 1000 5000 10000 20000 30000) gsize(6) ///
		plotregion(margin(-1 -1 0 0)) graphregion(margin(0 0 -20 -10)) xsize(7) ysize(4) ndsize(.05) osize(.04 .04 .04 .04 .04 .04 .04 .04) mosize(.05) ///
		name(UN, replace) 
		 
		graph combine UN durationbar, cols(1) iscale(.9) imargin(0 0 0 0)  
		graph export "Deployment Map UN Duration 2 B&W.pdf", replace
